package online.sanen.mhdt;

import online.sanen.mhdt.constant.AttrConstant;
import online.sanen.mhdt.entity.attr.*;
import sun.plugin.dom.core.Attr;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @author ys
 * @date 2019-09-26 16:56
 */
public class RandomeTool {
    public static int random(int val) {
        return (int) (Math.random() * (val + 1));
    }

    public static int equipBaseAttr(int minVal, int maxVal) {
        return random(maxVal - minVal) + minVal;
    }

    public static final int[][] baseAttr = {
            {AttrConstant.TYPE_STR, 5, 2},
            {AttrConstant.TYPE_MAG, 5, 2},
            {AttrConstant.TYPE_CON, 5, 2},
            {AttrConstant.TYPE_VIT, 5, 2},
            {AttrConstant.TYPE_AGI, 5, 2},
            {AttrConstant.TYPE_HP, 80, 20},
            {AttrConstant.TYPE_MP, 50, 12}};

    public static List<Attribute> getAttrs(int level) {
        List<Attribute> list = new ArrayList<>();
        //随机1-3条属性
        int num = random(2) + 1;
        for (int i = 0; i < num; i++) {
            Attribute attr = getAttr(level);
            if(attr!=null)list.add(attr);
        }
        return list;
    }

    public static Attribute getAttr(int level) {
        int[] arr = baseAttr[random(baseAttr.length - 1)];
        int val = random(arr[2] * (level / 10 + 1)) + arr[1];
        int type = arr[0];
        switch (type) {
            case AttrConstant.TYPE_STR:
                return new STR(val);
            case AttrConstant.TYPE_MAG:
                return new MAG(val);
            case AttrConstant.TYPE_CON:
                return new CONS(val);
            case AttrConstant.TYPE_VIT:
                return new VIT(val);
            case AttrConstant.TYPE_AGI:
                return new AGI(val);
            case AttrConstant.TYPE_HP:
                return new HP(val);
            case AttrConstant.TYPE_MP:
                return new MP(val);
        }
        return null;
    }

    public static void main(String[] args){
        int level=120;
        System.out.println(getAttrs(level));
//        System.out.println(getAttrs(level));
//        System.out.println(getAttrs(level));
//        System.out.println(getAttrs(level));
//        System.out.println(getAttrs(level));
    }
}
